package com.tripupdater.command
{
	import com.tripupdater.model.Params;
	import com.tripupdater.type.SkypeStatusType;
	import com.tripupdater.view.SkypeView;
	import com.turner.caf.commands.ICommand;
	import com.turner.caf.control.CAFEvent;
	
	import flash.net.NetConnection;
	import flash.net.Responder;

	public class GetSkypeStatusCommand implements ICommand
	{
		private var viewTarget:SkypeView;
		
		public function GetSkypeStatusCommand()
		{
		}

		public function execute(event:CAFEvent):void
		{
			viewTarget= event.viewTarget as SkypeView;
			
			var gatewayUrl:String= Params.HOST + "/flashservices/gateway.php";
			var service:NetConnection= new NetConnection();
			var responder:Responder= new Responder(result, fault);
			service.connect(gatewayUrl);
			service.call("Skype.getStatus", responder, Params.SKYPE_USER);
		}
		
		private function result(data:Object):void
		{
			viewTarget.setSkypeStatus(data as String);
		}
		
		private function fault(data:Object):void
		{
			trace("Error! " + data);
			viewTarget.setSkypeStatus(SkypeStatusType.OFFLINE);
		}
	}
}